package mall.service;

import mall.dao.OrderDao;
import mall.dao.OrderDaoImpl;
import mall.model.bo.ChangeOrderBO;
import mall.model.bo.PageOrderBO;
import mall.model.vo.OrderInfoVO;
import mall.model.vo.PageOrderInfoVO;
import mall.model.vo.PageOrdersVO;
import mall.model.vo.SpecVO;

import java.util.List;

/*
 *
 * @author Yonni
 * @version 1.8.0_201
 * @date 2020-05-30 09:09
 *
 * */
public class OrderServiceImpl implements OrderService {
    private OrderDao orderDao = new OrderDaoImpl();

    @Override
    public PageOrdersVO ordersByPage(PageOrderBO orderBO) {
        int totalCounts = orderDao.getTotalCounts(orderBO);
        //查询当前分页的结果 page1: 1-5 page2: 6-10
        List<PageOrderInfoVO> orderInfoVOS = orderDao.ordersByPage(orderBO);
        PageOrdersVO pageOrdersVO = new PageOrdersVO();
        pageOrdersVO.setTotal(totalCounts);
        pageOrdersVO.setOrders(orderInfoVOS);
        return pageOrdersVO;
    }

    @Override
    public OrderInfoVO order(String id) {
        //获取order表中对应的goodsId
        int goodsId = orderDao.getGoodsId(id);

        //根据goodsId获取该商品的spec信息
        List<SpecVO> specVOS = orderDao.getSpecVOS(goodsId);

        OrderInfoVO orderInfoVO = orderDao.order(id);
        orderInfoVO.setSpec(specVOS);

        return orderInfoVO;
    }

    @Override
    public void changeOrder(ChangeOrderBO changeOrderBO) {
        orderDao.changeOrder(changeOrderBO);
    }

    @Override
    public void deleteOrder(String id) {
        orderDao.deleteOrder(id);
    }
}
